<template>
  <div class="home">
    <div class="top">
      <span>饿了么</span>
    </div>
  <van-search
  v-model="value"
  shape="round"
  background="	#00BFFF"
  placeholder="请输入搜索关键词"
/>
<div class="banner">
  <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
  <van-swipe-item v-for="(item,index) in bannerlist" :key="index">
    <img :src="item.bannerUrl" alt="">
  </van-swipe-item>
</van-swipe>
</div>
<div class="boxone">
        <div class="like">
            <p>猜你喜欢</p>
        <div class="box1" >
            <span @click="dissclick(index)" v-for="(item,index) in tasklist" :key="index">{{item.text}}</span>
        </div>
        <div class="box2">
            <div class="one">年货节热卖</div>
            <div class="one">津贴联盟</div>
            <div class="one">满减优惠</div>
            <div class="one">品质联盟</div>
        </div>
        </div>
        <div class="box-item" >
            <div @click="todiscounts(item.mtWmPoiId)" class="box-discounts" v-for="(item,index) in shoplist" :key="index">
                <img :src="item.picUrl" alt="">
            <div class="item">
                <div class="name">{{item.name}}</div>
                <div class="distance">{{item.distance}}</div>
                <div class="minPriceTip">{{item.minPriceTip}}</div>
                <div class="monthSalesTip">{{item.monthSalesTip}}</div>
                <div class="shippingFeeTip">{{item.shippingFeeTip}}</div>
            </div>
         </div>
           
        </div>
      
    </div>
  
  </div>
</template>
<script setup>
import { ref,onMounted } from 'vue';
 import { banner_list,shop_list,shop_shopinfo } from "../../api/api";
 import { useRouter } from "vue-router";
 import { useRoute } from "vue-router";
 var $router = useRouter()
 var $route = useRoute()
 var currentIndex = ref(0)
    const value= ref('');
   var bannerlist =ref([])
   var shoplist=ref([])
   var tasklist=ref([{text:'综合排序▽'} ,{text:'距离最近'},{text:'销量最高'},{text:'筛选☟'},])
   var todiscounts=(id)=>{
    console.log(444);
       $router.push('/detail/'+id)
       console.log(id);
   }
   var dissclick=(index)=>{
     currentIndex.value=index
     if (currentIndex.value == 1) {
               shoplist.value.sort((a, b) => {
                    return parseFloat(a.distance) - parseFloat(b.distance);
                });
      }
     if (currentIndex.value == 2) {
               shoplist.value.sort((a, b) => {
                return parseInt(b.monthSalesTip.substring(2)) - parseInt(a.monthSalesTip.substring(2));
                });
      }
   }
  onMounted(()=>{
    shop_list().then((res)=>{
    shoplist.value=res.data.list
      console.log(res.data.list);
    })
    banner_list().then((res)=>{
      bannerlist.value=res.data.list
      console.log(res.data.list);
    })
    shop_shopinfo({params:{id:943030044198977}}).then((res)=>{
        if(res.data.code==200){
            console.log(res.data.shopinfo);
        }else if(res.data.code==400){
            $router.go(-1)
        }
    })
  })
</script>
<style scoped>
.top{
  width: 100%;
  height: 100%;
  text-align: center;
  font-size: 30px;
  color: white;
  background-color:#00BFFF ;
}
.banner{
  width: 100%;
  height: 100%;
}
.banner image{
    width: 100%;
}
.my-swipe img {
  width: 100%;
  height: 100%;
  }
  .boxone{
    margin-left: 15px;
    margin-right: 15px;
}
.box1{
    display: flex;
    justify-content: space-around;
    margin-bottom: 10px;
}
.one{
    font-size: 12px;
    width: 72px;
    height: 29px;
    text-align: center;
    line-height: 29px;
    background-color: rgb(230, 222, 222);
    border-radius:5px ;
}
.box2{
    display: flex;
    justify-content: space-around;
}
.b1{
    font-size: 17px;
    font-weight: bold;
}
.box-item{
    width: 100%;
    height: 300px;
    overflow: auto;
    
}
.box-discounts{
    display: flex;
    margin-bottom: 20px;

    padding: 10px;
}
.box-discounts img{
    width: 100px;
    height: 100px;
    margin-right: 5px;
}

</style>
